package livingarea.actions_impl;

import livingarea.actions.SpawnType;
import livingarea.Members.Beast;
import livingarea.Members.Factory.AreaMemberFactory;
import livingarea.Members.Factory.PrayFactory;
import livingarea.Members.Pray;

/**
 * Class incapsulate <code> spawn() </code> method and realized spawn action of
 * pray beast.
 *
 * @author Muzalevskiy Vitaliy
 */
public class PraySpawn implements SpawnType {
    
    /**<code> Beast </code> object that delegate object of current class.*/
    private Beast beast;
    
    /**
     * Constructor for current class.
     *
     * @param beast - <code> Beast </code> object that delegate object of 
     *      current class.
     */
    public PraySpawn(Beast beast){
        this.beast = beast;
    }

    /**
     * Current method make pray beast to spawn after specified number of
     * iterations.
     */
    @Override
    public void spawn() {
        if((beast.getLifeCount() != 0) && (beast.getLifeCount() % Pray.MOVES_TO_SPAWN) == 0){
            AreaMemberFactory prayFactory = new PrayFactory();
            prayFactory.create(beast.getLivingArea(), beast.getPosition());
            beast.getLivingArea().getStatistics().increasePrayCount();
        }  
    }
    
}
